package com.sgcc.fj.pmos.e_fj_home.activity;

import android.text.TextUtils;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.StringUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseActivity;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.fj.pmos.e_fj_home.bean.DLYHQYYDXXBean;
import com.sgcc.fj.pmos.e_fj_home.bean.IformenCodeBean;
import com.sgcc.fj.pmos.e_fj_home.contract.DLYHQYYDXXContract;
import com.sgcc.fj.pmos.e_fj_home.presenter.DLYHQYYDXXPresenter;

import java.util.List;

/**
 * 电力用户-----企业用电信息
 */
@Route(path = HomeArouterPath.HOME_DLYHQYYDXX)
public class DLYHQYYDXXActivity extends MvpBaseActivity<DLYHQYYDXXPresenter> implements DLYHQYYDXXContract.View {

    private String applyId = "", name = "";
    private TextView mTvFrom;
    private TextView mTvTime;
    private TextView mTvRange;
    private TextView mTvNumber;
    private String mOperateDate, mPublishType, mReadAmount;
    private List<IformenCodeBean.DataBean.ChildrenBean> mList;
    private TitleBar mTitleBar;
    private TextView mTvBusinessLicenseInformation1;
    private TextView mTvBusinessLicenseInformation2;
    private TextView mTvBusinessLicenseInformation3;
    private TextView mTvBusinessLicenseInformation4;
    private TextView mTvBusinessLicenseInformation5;
    private TextView mTvBusinessLicenseInformation6;
    private TextView mTvBusinessLicenseInformation7;
    private TextView mTvBusinessLicenseInformation8;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_dlyhqyydxx;
    }

    @Override
    protected void initViews() {
        super.initViews();
        applyId = getIntent().getStringExtra("guid");
        name = getIntent().getStringExtra("sourceName");
        mOperateDate = getIntent().getStringExtra("operateDate");
        mPublishType = getIntent().getStringExtra("publishType");
        mReadAmount = getIntent().getStringExtra("readAmount");
        mPresenter.uniformencode();

        findViewByIds();
    }

    private void findViewByIds() {
        mTitleBar = (TitleBar) findViewById(R.id.title_bar);
        mTvFrom = (TextView) findViewById(R.id.tv_from);
        mTvTime = (TextView) findViewById(R.id.tv_time);
        mTvRange = (TextView) findViewById(R.id.tv_range);
        mTvNumber = (TextView) findViewById(R.id.tv_number);
        mTvBusinessLicenseInformation1 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation1);
        mTvBusinessLicenseInformation2 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation2);
        mTvBusinessLicenseInformation3 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation3);
        mTvBusinessLicenseInformation4 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation4);
        mTvBusinessLicenseInformation5 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation5);
        mTvBusinessLicenseInformation6 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation6);
        mTvBusinessLicenseInformation7 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation7);
        mTvBusinessLicenseInformation8 = (TextView) findViewById(R.id.tv_BusinessLicenseInformation8);

        mTitleBar.setTitle(name + "企业用电信息");
        mTvFrom.setText(name);
        String time = "";
        try {
            time = StringUtils.isEmpty(DateUtils.getStrng_to_Times_ymdhms1(mOperateDate)) ?
                    DateUtils.get_TimesYMDHMSG1(mOperateDate) :
                    DateUtils.getStrng_to_Times_ymdhms1(mOperateDate);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        mTvTime.setText(time);
        mTvRange.setText(mPublishType);
        mTvNumber.setText(mReadAmount);
    }

    @Override
    protected DLYHQYYDXXPresenter createPresenter() {
        return new DLYHQYYDXXPresenter();
    }

    @Override
    public void getDataSuccess(DLYHQYYDXXBean response) {
        DLYHQYYDXXBean.DataBean bean = response.getData();
        mTvBusinessLicenseInformation1.setText(TextUtils.isEmpty(bean.getTradeCode()) ? "" : "100".equals(bean.getTradeCode()) ? "大工业用电" : "");
        mTvBusinessLicenseInformation2.setText(bean.getGeoGrRegionName());
        mTvBusinessLicenseInformation3.setText(bean.getYearYdinfo());
        mTvBusinessLicenseInformation4.setText(queryStr(bean.getVoltageLevel()));
        mTvBusinessLicenseInformation5.setText(bean.getGdfs());
        mTvBusinessLicenseInformation6.setText(bean.getZbdy());
        mTvBusinessLicenseInformation7.setText(bean.getByqbzrl());
        mTvBusinessLicenseInformation8.setText(bean.getZuidayqldj());
    }

    @Override
    public void getDataFailed() {

    }

    @Override
    public void uniformencodeSuccess(IformenCodeBean response) {
        if (response.getData().getChildren() != null) {
            if (response.getData().getChildren().size() > 0) {
                mList = response.getData().getChildren();
            }
        }
    }

    @Override
    public void uniformencodeFailed() {

    }

    private String queryStr(String encode) {
        String result = "";
        for (IformenCodeBean.DataBean.ChildrenBean bean : mList) {
            if (encode.equals(bean.getEncode())) {
                result = bean.getEncodeValue();
            }
        }
        return result;
    }

}
